home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWStream / Include / FWASinks.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-08  |  3.9 KB  |  141 lines  |  [TEXT/MPS ]

  1. #ifndef FWASINKS_H
  2. #define FWASINKS_H
  3. //========================================================================================
  4. //
  5. //    File:                FWASinks.h
  6. //    Release Version:    $ 1.0d11 $
  7. //
  8. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWAUTODE_H
  13. #include "FWAutoDe.h"
  14. #endif
  15.  
  16. #if FW_LIB_EXPORT_PRAGMAS
  17. #pragma lib_export on
  18. #endif
  19.  
  20. //========================================================================================
  21. //    CLASS FW_CSink
  22. //========================================================================================
  23.  
  24. class FW_CLASS_ATTR FW_CSink FW_AUTO_DESTRUCT_OBJECT
  25. {
  26.  
  27. public:
  28.  
  29.     FW_CSink();
  30.     virtual ~ FW_CSink();
  31.  
  32. // ---- Standard sink protocol
  33.     
  34.     virtual long GetReadableBytes() const = 0;
  35.     virtual void Read(void * destination, long count) = 0;
  36.  
  37.     virtual long GetWritableBytes() const = 0;
  38.     virtual void Write(const void* source, long count) = 0;
  39.  
  40. public:
  41.     
  42. // ---- Optimized sink protocol
  43.  
  44.     // These four methods make it possible to optimize sink access
  45.     // to buffered devices that can expose their buffer.
  46.     // Sinks that are not buffered, or cannot expose their buffer
  47.     // will not be able to take advantage of this protocol.  Such
  48.     // sinks should not override these methods, as the default behavior
  49.     // is correct in that case.
  50.     
  51.     // Note that the ODF Stream classes will take advantage of this
  52.     // protocol for sinks that support it, but no other ODF classes
  53.     // will, and it is not expected that these methods would be used
  54.     // by other clients.  We could therefore grant friend access
  55.     // to the streams classes and then declare these functions
  56.     // to be private, but that seems unnecessarily restrictive.
  57.     
  58.     virtual const void* ReadPeek(long& availableReadBytes);
  59.     virtual void ReadPeekAdvance(long bytesRead);
  60.  
  61.     virtual void* WritePeek(long& availableWriteBytes);
  62.     virtual void WritePeekAdvance(long bytesWritten);
  63.     
  64. protected:
  65.     FW_CSink(const FW_CSink& sink);
  66.     FW_CSink& operator=(const FW_CSink& sink);
  67. };
  68.  
  69.  
  70. //========================================================================================
  71. //    FW_CRandomAccessSink
  72. //========================================================================================
  73.  
  74. class FW_CLASS_ATTR FW_CRandomAccessSink : public FW_CSink
  75. {
  76.  
  77. public:    
  78.  
  79.     FW_CRandomAccessSink();
  80.     virtual~ FW_CRandomAccessSink();
  81.  
  82.     virtual long GetReadableBytes() const;
  83.     
  84.     virtual long GetLength() const = 0;
  85.     virtual void SetLength(long length) = 0;
  86.     virtual long GetPosition() const = 0;
  87.     virtual void SetPosition(long position) = 0;
  88.  
  89. protected:
  90.     FW_CRandomAccessSink(const FW_CRandomAccessSink& sink);
  91.     FW_CRandomAccessSink& operator=(const FW_CRandomAccessSink& sink);
  92. };
  93.  
  94.  
  95. //========================================================================================
  96. //    CLASS FW_CMemorySink
  97. //========================================================================================
  98.  
  99. class FW_CLASS_ATTR FW_CMemorySink : public FW_CRandomAccessSink
  100. {
  101.  
  102. public:
  103.  
  104.     FW_CMemorySink(void* buffer, long capacity, long length=0);
  105.     virtual ~ FW_CMemorySink();
  106.     
  107.     virtual void Read(void * destination, long count);
  108.     
  109.     virtual long GetWritableBytes() const;
  110.     virtual void Write(const void* source, long count);
  111.  
  112.     virtual long GetLength() const;
  113.     virtual void SetLength(long length);
  114.     virtual long GetPosition() const;
  115.     virtual void SetPosition(long position);
  116.     
  117.     // ---- Peek optimization
  118.  
  119.     virtual const void* ReadPeek(long& availableReadBytes);
  120.     virtual void ReadPeekAdvance(long bytesRead);
  121.     virtual void* WritePeek(long& availableWriteBytes);
  122.     virtual void WritePeekAdvance(long bytesWritten);
  123.  
  124. private:
  125.  
  126.     char*    fBuffer;
  127.     const long    fCapacity;
  128.     long        fLength;
  129.     long    fPosition;
  130.     
  131.     FW_CMemorySink(const FW_CMemorySink& sink);
  132.     FW_CMemorySink& operator=(const FW_CMemorySink& sink);
  133.         // Shouldn't copy instances of this class.
  134. };
  135.  
  136. #if FW_LIB_EXPORT_PRAGMAS
  137. #pragma lib_export off
  138. #endif
  139.  
  140. #endif
  141.